const express = require('express')
const path = require('path')
const cookieSession = require('cookie-session')
let app = express()
app.listen(3000, () => {
    console.log('3000ok');
})


// 引入路由模块
let registerRouter = require("./routes/register")


// 开放静态资源
app.use("/public",express.static(path.join(__dirname,'./public')))

// post
app.use(express.urlencoded({extended:true}))
app.use(express.json())


// session
app.use(cookieSession({
    keys:["dasda","eqeq","czxcsaeqd"],
    maxAge:1000*60,
}))




// 注册路由中间件
app.use(registerRouter)



// 错误中间件
app.use((req, res) => {
    res.send({
        status: 404,
        msg: "此路径不存在"
    })
})

app.use((err,req, res,next) => {
    res.send({
        status: 500,
        msg: err
    })
})



